//
//  DHSearchSizeScrollView.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/1/21.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHSearchSizeScrollView.h"
#import "DHSearchSizeItemView.h"

@interface DHSearchSizeScrollView()

@end

@implementation DHSearchSizeScrollView

- (NSMutableArray *)sizesArr{
    if (!_sizesArr) {
        _sizesArr = [NSMutableArray array];
    }
    return _sizesArr;
}

// 获取品类对应尺码
- (void)loadSizeWithCatrgoryID:(NSString *)category_id{
    [[DHNetAPIClient shareDHNetAPIClient] request_category_sizes_nameWithCategoryID:category_id andBlock:^(id data, NSError *error) {
        [self.sizesArr removeAllObjects];
        [self.sizesArr addObjectsFromArray:[data objectForKey:@"sizes"]];
        [self updateSizesView];
    }];
}

- (void)updateSizesView{
    CGFloat W = 92;
    [self removeAllSubviews];
    __weak __typeof(self)weakSelf = self;
    self.contentSize = CGSizeMake(self.sizesArr.count * W, self.height);
    [self.sizesArr enumerateObjectsUsingBlock:^(NSString *sizeName, NSUInteger idx, BOOL * _Nonnull stop) {
        DHSearchSizeItemView *sizeItemView = [[DHSearchSizeItemView alloc] initWithFrame:CGRectMake(idx * W, 0, W, weakSelf.height) andSceneTitle:sizeName];
        [weakSelf addSubview:sizeItemView];
    }];
}

@end
